package com.zlq.cn.controller.sign.movie;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zlq.cn.api.SignApiResult;
import com.zlq.cn.bootstrap.SignApiBootstrap;
import com.zlq.cn.config.Config;
import com.zlq.cn.dto.param.MoviePageParam;
import com.zlq.cn.entity.Movie;
import com.zlq.cn.entity.MovieDisable;
import com.zlq.cn.entity.User;
import com.zlq.cn.service.movie.MovieDisableService;
import com.zlq.cn.service.movie.MovieService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Objects;

/**
 * <p>
 * 影片 前端控制器
 * </p>
 *
 * @author zhoucl
 * @since 2022-03-19
 */
@Api(tags = "影片-列表")
@RestController
@RequestMapping("/movie")
public class MovieController {

    @Resource
    private MovieService movieService;

    @Resource
    private MovieDisableService movieDisableService;

    @ApiOperation("分页获取影片列表")
    @PostMapping("/page")
    public SignApiResult<Page<Movie>> page(@RequestBody MoviePageParam moviePageParam) {
        return SignApiResult.resultSuccess(movieService.page(moviePageParam));
    }

    @ApiOperation("解析影片")
    @GetMapping("/parseMovie")
    public void parseMovie() {
        movieService.parseMovie();
    }

    @ApiOperation("解析影片评论")
    @GetMapping("/parseComment")
    public void parseComment() {
        movieService.parseComment();
    }

    @ApiOperation("封面保存到自己服务器")
    @GetMapping("/convertCover")
    public void convertCover() {
        movieService.convertCover();
    }

    @ApiOperation("屏蔽影片")
    @PostMapping("/disable")
    public SignApiResult<String> disable(@RequestBody Movie movie) {
        User user = SignApiBootstrap.requestUser();
//        if (Objects.isNull(user.getVipLevel()) || Config.LEVEL_ADMIN != user.getVipLevel()) {
//            return SignApiResult.resultError("无权限");
//        }
        Assert.notNull(movie.getMovieId(), "影片id不能为空");
        movieDisableService.save(new MovieDisable()
                .setUserId(user.getId())
                .setDataId(movie.getMovieId())
                .setType("MOVIE")
                .setDisable(1));
        return SignApiResult.resultSuccess("屏蔽成功");
    }
}

